package 刷题10月.leecodehot100;

import java.util.Scanner;
//截断二进制
public class Main3 {
    //到第一个为1的数时，转换为2进制
    public static  int isTrue(int n){
        int yushu=0;
        String str = "";
        int weishu=0;
        String count="";
        while(n!=0){
            yushu=n%2;
            str = yushu+str;
            n = n/2;
            if(yushu==1){
                break;
            }
        }
        return Integer.parseInt(str);
    }
    //将1右边的0都变为1
    public  static int change(int code){
        String a=String.valueOf(code);
        char s[]=a.toCharArray();
        StringBuffer ss=new StringBuffer();
        for (int i = 0; i <s.length ; i++) {
            if(s[i]=='1'){
                ss.append('1');
            }
            else if(s[i]=='0'){
                ss.append('1');
            }
        }
        return Integer.parseInt(ss.toString());
    }
    //二进制转换为10进制
    public static int changeInt(int code){
        String res = String.valueOf(code);
        int ress=Integer.parseInt(res,2);
        return ress;
    }
    public static int sum(long n){
        int sum=0;
        for (int i = 0; i < n; i++) {
            sum+=changeInt(change(isTrue(i+1)));
        }
        return sum;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x=0;
        int arr[]=new int[n];
        for(int i = 0; i < n; i++){
            x = sc.nextInt();
            arr[i]=sum(x);
        }
        for(int a:arr){
            System.out.println(a);
        }
        sc.close();
    }
}
